package com.umanji.security.service;

import java.util.List;

import java.util.logging.Logger;

import javax.persistence.EntityManager;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

// import com.umanji.user.dao.UserDao;
import com.umanji.generic.service.GenericService;
import com.umanji.security.domain.Users;
import com.umanji.user.domain.Members;

@Service("securityUserService")
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public class UserServiceImpl extends GenericService<Users, Long> implements UserService {

	// private final Log log = LogFactory.getLog ( UserServiceImpl.class );

	@Override
	public Users findByUsername(String username) {
		// super.entityManager.createQuery("Select p from Person p where p.lastName = :lastName").setParameter("lastName", lastName).getResultList();
		return (Users) em.createQuery("Select t from " + Users.class.getSimpleName() + " t where t.username = :username").setParameter("username", username).getSingleResult();
	}

	/*@Override
	public void update(Users entity) {
		em.createQuery("update from "+Users.class.getSimpleName()+" set password = "+entity.getPassword()+" where username = "+entity.getUsername());
		//Query q = ((Query) em.createQuery("update from "+Users.class.getSimpleName()+" t set t.userpassword = :password where t.username = :username")).setProperty("password",entity.getPassword())
	    //.setProperty("username",entity.getUsername());
	  //q.executeUpdate();
	}*/
}
